import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtContentPostApi {
  export interface Post {
    id?: number;
    communityId?: number;
    merchantId?: number;
    categoryId?: number;
    userId?: number;
    postType?: number;
    title?: string;
    content?: string;
    images?: string;
    videos?: string;
    attachments?: string;
    tags?: string;
    likeCount?: number;
    commentCount?: number;
    shareCount?: number;
    viewCount?: number;
    isTop?: number;
    isHot?: number;
    isEssence?: number;
    auditStatus?: number;
    auditUserId?: number;
    auditTime?: string;
    auditRemark?: string;
    createTime?: string;
  }

  export interface PostPageReqVO extends PageParam {
    title?: string;
    postType?: number;
    categoryId?: number;
    userId?: number;
    auditStatus?: number;
    isTop?: number;
    isHot?: number;
    isEssence?: number;
    createTime?: string[];
  }
}

export function getPostPage(params: CmtContentPostApi.PostPageReqVO) {
  return requestClient.get<PageResult<CmtContentPostApi.Post>>(
    '/cmt/content-post/page',
    { params },
  );
}

export function getPost(id: number) {
  return requestClient.get<CmtContentPostApi.Post>(
    `/cmt/content-post/get?id=${id}`,
  );
}

export function createPost(data: CmtContentPostApi.Post) {
  return requestClient.post('/cmt/content-post/create', data);
}

export function updatePost(data: CmtContentPostApi.Post) {
  return requestClient.put('/cmt/content-post/update', data);
}

export function deletePost(id: number) {
  return requestClient.delete(`/cmt/content-post/delete?id=${id}`);
}

export function deletePostList(ids: number[]) {
  return requestClient.delete(
    `/cmt/content-post/delete-list?ids=${ids.join(',')}`,
  );
}

export function exportPost(params: CmtContentPostApi.PostPageReqVO) {
  return requestClient.download('/cmt/content-post/export-excel', { params });
}
